function PuzzleUI() {


    var box_main=$('.wgt-puzzle');    //控件

    var data_counttime= $('.counttime span', box_main),
        data_originalimage= $('.imgbox','#popup');
    var btn_play= $('.btn-play', box_main),
        btn_pause= $('.btn-pause', box_main),
        btn_continue= $('.btn-continue', box_main),
        btn_again = $('.btn-again', box_main);
    var box_loading= $('.puzzle-loading',box_main);

    var Game= Puzzle();

    function setUI(status) {
        switch (status){
            case 0:
                data_counttime.hide();
                data_originalimage.hide();
                btn_play.hide();
                btn_pause.hide();
                btn_continue.hide();
                btn_again.hide();
                box_loading.show();
                break;
            case 1:
                data_counttime.hide();
                data_originalimage.hide();
                btn_play.show();
                btn_pause.hide();
                btn_continue.hide();
                btn_again.hide();
                box_loading.hide();
                break;
            case 2:
                data_counttime.show();
                data_originalimage.hide();
                btn_play.hide();
                btn_pause.show();
                btn_continue.hide();
                btn_again.hide();
                box_loading.hide();
                break;
            case 3:
                data_counttime.show();
                data_originalimage.hide();
                btn_play.hide();
                btn_pause.hide();
                btn_continue.show();
                btn_again.hide();
                box_loading.hide();
                break;
            case 4:
                data_counttime.show();
                data_originalimage.hide();
                btn_play.hide();
                btn_pause.hide();
                btn_continue.hide();
                btn_again.show();
                box_loading.hide();
                break;
            case 5:
                data_counttime.hide();
                data_originalimage.hide();
                btn_play.hide();
                btn_pause.hide();
                btn_continue.hide();
                btn_again.show();
                box_loading.hide();
                break;
        }
    }


    function setHandleLoading(fn) {
        Game.setHandleLoading(function (container) {
            box_main.append(container);
            setUI(0);    //设置UI
            fn();
        });
    }
    function setHandleReady(fn) {
        Game.setHandleReady(function () {
            setUI(1);    //设置UI
            fn();
        });
    }
    function setHandleCountTime(fn) {
        Game.setHandleCountTime(function (time) {
            data_counttime.text('拼图倒计时：'+time+'秒');
            fn(time);
        });
    }
    function setHandleGameSuccess(fn) {
        Game.setHandleGameSuccess(function () {
            setUI(4);    //设置UI
            fn();
        });
    }
    function setHandleGameFail(fn) {
        Game.setHandleGameFail(function () {
            setUI(5);    //设置UI
            fn();
        });
    }

    function gameStart() {
        Game.start({
            success: function (status) {
                switch (status) {
                    case 1: console.log('success:','游戏已启动'); setUI(2); break;
                    case 3: console.log('success:','游戏继续'); setUI(2); break;
                }
            },
            error: function (status) {
                switch (status) {
                    case 0: console.log('error:','装载中'); break;
                    case 2: console.log('error:','运行中'); break;
                    case 4: console.log('error:','游戏成功，点击Again再来一局'); break;
                    case 5: console.log('error:','游戏超时失败，点击Again再来一局'); break;
                }
            }
        });
    }
    function gamePause() {
        setUI(3);
        Game.pause();
    }

    btn_play.on('click', gameStart);
    btn_pause.on('click', gamePause);
    btn_continue.on('click', gameStart);
    btn_again.on('click', Game.again);

    return {
        install: Game.install,
        config: Game.config,
        setHandleLoading: setHandleLoading,
        setHandleReady: setHandleReady,
        setHandleCountTime: setHandleCountTime,
        setHandleGameSuccess: setHandleGameSuccess,
        setHandleGameFail: setHandleGameFail
    };
};